package edu.nf.exam.dao.impl;

import edu.nf.exam.dao.LogInfoDao;
import edu.nf.exam.entity.LogInfo;
import edu.nf.exam.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Author : QYM
 * @create 2021/6/17
 * 用户日志表--接口实现类
 */
public class LogInfoDaoImpl implements LogInfoDao {
    /**
     * 添加日志
     * @param logInfo
     * @return
     */
    @Override
    public int add(LogInfo logInfo) {
        SqlSession sqlSession= MyBatisUtil.getSqlSession(true);
        int r = sqlSession.getMapper(LogInfoDao.class).add(logInfo);
        sqlSession.close();
        return r;
    }

    /**
     * 查询所有日志
     * @param logInfo
     * @return
     */
    @Override
    public List<LogInfo> selectAll(LogInfo logInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<LogInfo> list = sqlSession.getMapper(LogInfoDao.class).selectAll(logInfo);
        sqlSession.close();
        return list;
    }

    /**
     * 分页查询所有日志
     * @param userId
     * @param userName
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<LogInfo> selectByPage(Integer userId, String userName, Integer pageNum, Integer pageSize) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<LogInfo> list = sqlSession.getMapper(LogInfoDao.class).selectByPage(userId,userName,pageNum,pageSize);
        sqlSession.close();
        return list;
    }

    /**
     * 根据日期查询当天的日志数
     * @param createTime
     * @return
     */
    @Override
    public List<LogInfo> selectByCreateTime(String createTime) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<LogInfo> list = sqlSession.getMapper(LogInfoDao.class).selectByCreateTime(createTime);
        sqlSession.close();
        return list;
    }
}
